<?php

function list_grade(){
	my_set_code_js('
		function confirmDelete(id){
			var t = confirm(\'Yakin akan menghapus data ?\');
			if(t){
				location.href=\'index.php?com='.$_GET['com'].'&task=delete&id=\'+id;
			}
			return false;
		}
	');
	
	$header = array(
		'Grade '=>array('style'=>'text-align:left;border-bottom:2px solid;width:90%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	);
	$query = "SELECT * FROM grade ORDER BY grade_id ASC ";
	$result = my_query($query);
	$row = array();

	while($ey = my_fetch_array($result) ){

		$temp = my_fetch_array(my_query("SELECT MAX(grade_id) as max FROM grade ")) ;
		$max_grade=$temp['max'];
		$temp = my_fetch_array(my_query("SELECT MAX(grade_id) as max FROM gol_grade ")) ;

		if($max_grade<$temp['max']+1){
			$max_grade=$temp['max']+1;
		}	
		$temp = my_fetch_array(my_query("SELECT MAX(grade_id) as max FROM struktur_gaji_detail ")) ;
		if($max_grade<$temp['max']+1){
			$max_grade=$temp['max']+1;
		}	
		if($ey['grade_id'] < $max_grade ){		
			$delete_button = button_icon( 'b_drop_off.png' , ''  );
		}else{
			$deleteproperty = array(
				'href'=>'javascript:;',
				'title'=>'Delete',
				'onclick'=>'confirmDelete('.$ey['grade_id'].')',
			);
			$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );
		}
		
		$row[] = array(
			'kode'=>  $ey['kode_grade'] ,     
			'operasi'=> position_text_align( $delete_button , 'right'),
		);
	}
	$datas = table_rows($row);
	return table_builder($header , $datas ,  5 , false );
}

function form_grade_create(){
		$temp = my_fetch_array(my_query("SELECT MAX(grade_id) as max FROM grade ")) ;
		$max_grade=$temp['max'];
		$gid=$max_grade+1;

	$datas = array(
			'grade_id'=>my_type_data_int($gid), 		 	 	 	 	 	 	 
			'kode_grade'=>my_type_data_str($gid), 		 	 	 	 	 	 	 
		);
	return my_insert_record('grade' , $datas);
}

function delete_grade($grade_id){
	$query = "DELETE FROM grade WHERE grade_id ={$grade_id} ";
	return my_query($query);
}	

